// page/pay/pay.js
var util = require('/../../utils/utils.js');
const db = wx.cloud.database({
  env:'test-7gxzn7uuc171e9e9'
})
const order = db.collection("order")
const $ = db.command.aggregate
const _ = db.command
Page({

  /**
   * 页面的初始数据
   */
  data: {
    total:0,
    count:0,
    text:[]
  },
  
 /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
     this.setData({
      total: options.total,
      count: options.count,
      address:options.address,
      order_id:options.order_id
   }),

   order.where({//从数据库获取订单的数据
    _id:this.data.order_id
  }).get().then(res=>{
    console.log(res)
    this.setData({
      text: res.data
    })
  })
  },

  jumpPage:function() {
    
    let that = this;

    var time = util.formatTime(new Date())
    order.doc(that.data.order_id).update({//点击支付完成之后给订单添加，位置和时间，以及ifpay：true
			data:{
        address:that.data.address,//参数未成功传递
        date:time,
        ifpay:true
			},
		})

    wx.navigateTo({
      url: '/page/order/order?total='+that.data.total+'&count='+that.data.count+'&address='+that.data.address,
    })
  },

  jumpPage2:function() {
    wx.navigateBack({
      delta: 1,
    })
  },
	location(e){//定位功能
		var that = this;
		wx.getLocation({
			type: "wgs84",
			success(res) {
					wx.chooseLocation({
							latitude: res.latitude,
							longitude: res.longitude,
							success: function(data){
								console.log(data)
								//data : address name
								that.setData({
									address:data.name
								})
							}
					})
			}
		})
	},
})